﻿using DevExpress.XtraEditors;
using SX_MesProject.Dtos.LJQDtos;
using SX_MesProject.Dtos;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static SX_MesProject.HttpClientHelper;
using SX_MesProject.Dtos.SchedulingTasksDTO;
using SX_MesProject.Dtos.ZFYDto;
using SX_MesProject.Dtos.SchedulingDTO;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Columns;
using System.Windows.Controls;

namespace SX_MesProject.SchedulingTasks
{
    public partial class SchedulingTasksList : DevExpress.XtraEditors.XtraForm
    {
        public SchedulingTasksList()
        {
            InitializeComponent();
        }

        private void SchedulingTasksList_Load(object sender, EventArgs e)
        {
            _ = Databinds();
            // 创建一个按钮列
            GridColumn buttonColumn = new GridColumn();
            buttonColumn.Caption = "开始";
            buttonColumn.FieldName = "EditButton";  // 用于标识这一列
            buttonColumn.Visible = true;

            // 创建一个 RepositoryItemButtonEdit（按钮编辑器）
            RepositoryItemButtonEdit buttonEdit = new RepositoryItemButtonEdit();
            buttonEdit.Buttons[0].Caption = "开始"; // 设置按钮显示文本
            buttonEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor; // 隐藏文本框，只显示按钮

            // 将 RepositoryItemButtonEdit 添加到 GridControl 的 RepositoryItems 集合
            gridControl1.RepositoryItems.Add(buttonEdit);

            // 将该列的编辑器设置为 RepositoryItemButtonEdit
            buttonColumn.ColumnEdit = buttonEdit;

            // 将列添加到 GridView 中
            gridView1.Columns.Add(buttonColumn);


            // 订阅 RepositoryItemButtonEdit 的 CustomButtonClick 事件
            buttonEdit.ButtonClick += ButtonEdit_ButtonClick;


        }
        private async Task Databinds()
        {
            try
            {
                PageInPut schedulingtasksinput = new PageInPut();
                schedulingtasksinput.pageSize = 10;
                schedulingtasksinput.pageIndex = 1;
                var list = await HttpClientHelper.RequestUrl<PageInPut, ApiResult<FenYeDTO<SchedulingTasksDTO>>>("https://localhost:44556/", "GetSchedulingTasksShow", MethodType.POST, schedulingtasksinput);
                this.gridControl1.DataSource = list.Data.data;



            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            SchedulingTasksAdd schedulingTasksAdd = new SchedulingTasksAdd();
            schedulingTasksAdd.OnLoadData += Databinds;
            schedulingTasksAdd.ShowDialog();
        }


        private void ButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            // 获取当前行的句柄（索引）
            int focusedRowHandle = gridView1.FocusedRowHandle;

            if (focusedRowHandle >= 0) // 如果选中行有效
            {
                Hint hint = new Hint();
                hint.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选中一行");
            }
        }




    }
}